<!DOCTYPE html>
<%@ page language="java" import="com.compuvest.web.*" pageEncoding="UTF-8" %>

<%@ taglib uri="/WEB-INF/tld/head.tld" prefix="head" %>

<jsp:useBean id="sb" class="SQLBean" scope="application"/>
<jsp:useBean id="advertShow" class="AdvertShow" scope="application"/>
<jsp:useBean id="basket" class="Basket" scope="session"/>
<%!
    public static final String[] messagesCF = { 
/* 0 */	"<p>Your password is incorrect</p>",
/* 1 */	"<p>This email is not registered in our database</p>",
/* 2 */	"<p>Email or password cannot be empty</p>",
/* 3 */	"<p>You are a registered Reseller. Please use 'Returning Reseller' section above</p>",
/* 4 */	"",
    };
%>
<%
    if(basket.getReseller()) {
	response.sendRedirect(application.getInitParameter("http") + "ItemsReseller.jsp");
	return;
    }

    String formURL = application.getInitParameter("https") + "ResellerForm.jsp";

    int forms = 0;
    String errorMess = "";
    String email = advertShow.getString(request.getParameter("Email"), "");
    String password = advertShow.getString(request.getParameter("Password"), "");

    String mode = request.getParameter("mode");
    if(mode != null) {
	if("old".equals(mode)) {
            forms = 1;
            if(!"".equals(email) && !"".equals(password)) {
		Customer cust = sb.getCustomer(email, password);
		if(cust.getCustomerID() > 0) { // present
                    basket.setCustomer(cust);
                    basket.setReseller("R".equals(cust.getType()) ? true : false);
                    response.sendRedirect(application.getInitParameter("http") + "ItemsReseller.jsp");
                    return;
		}
		else if(cust.getCustomerID() == 0) { // name present - passwd not correct
                    errorMess = messagesCF[0];
		}
		else if(cust.getCustomerID() == -1) { // new reseller
                    errorMess = messagesCF[1];
		}
            }
            else errorMess = messagesCF[2];
	}
	else if("new".equals(mode)) {
            forms = 2;
            if(!"".equals(email) && !"".equals(password)) {
		int result = sb.checkCustomer(email);
		if(result == 0) { // make new
                    Customer cust = new Customer();
                    cust.setEmail(email);
                    cust.setPassword(password);
                    cust.setCustomerID(0);
                    cust.getBilling().setCountry("US");
                    cust.getShipping().setCountry("US");
                    cust.setType("C");

                    basket.setCustomer(cust);

                    response.sendRedirect(application.getInitParameter("https") + "Reseller.jsp");
                    return;
		}
		else if(result == -1) { // customer present
                    errorMess = messagesCF[3];
		}
            }
            else errorMess = messagesCF[2];
	}
    }
%>
<html>
<head>
<title><%= application.getInitParameter("CompanyName") %></title>
<%@include file="./incl/scripts.txt" %>
</head>
<body>

<div id='cvbody'>

 <head:show />

 <div id='cvcont'>
  <table id='cvmain'>
  <colgroup><col width='80px'/><col width='*'/><col width='80px'/></colgroup>
  <tbody>
   <tr>
    <td id='cvleft' valign="top">

    </td>
    <td id='cvcenter' align="center" valign="top">

<form id="returncustomer" action="<%= formURL %>" onSubmit='return isReady(this)' method='POST' enctype="application/x-www-form-urlencoded">
<input type='hidden' name='mode' value='old'/>
<table id='cfrm_tb'>
 <colgroup><col span='2' width='50%'/></colgroup>
 <tr><td class='bsm' colspan='2'><span>Returning Reseller</span></td></tr>
 <tr height='90'>
  <td><div><%= (forms == 1) ? errorMess : "" %></div></td>
  <td class='brd'>
   <p>e-mail : <input maxlength='64' type='text' name='Email'/></p>
   <p>Password : <input maxlength='15' type='password' name='Password'/></p>
  </td>
 </tr>
 <tr>
  <td class='bsm' align='left'><a class='btlgr' href='<%= application.getInitParameter("https") %>CustomerForm.jsp'>Forgot password ?</a></td>
  <td class='bsm' align='right'><input type='submit' value='Go to my account'/></td>
 </tr>
</table>
</form>
<br/>

<form id="newcustomer" action="<%= formURL %>" method='POST' onSubmit='return isReady(this)' enctype="application/x-www-form-urlencoded">
<input type='hidden' name='mode' value='new'/>
<table id='cfrm_tb'>
 <colgroup><col span='2' width='50%'/></colgroup>
 <tr><td class='bsm' colspan='2'><span>New Reseller</span></td></tr>
 <tr height='90'>
  <td><div><%= (forms == 2) ? errorMess : "" %></div></td>
  <td class='brd'>
   <p>e-mail : <input maxlength='128' type='text' name='Email'/></p>
   <p>Password : <input maxlength='15' type='password' name='Password'/></p>
   <p>Confirm Password : <input maxlength='15' type='password' name='vPassword'/></p>
  </td>
 </tr>
 <tr height='26'>
  <td colspan='2' class='bsm' align='right'>
   <input type='submit' value='Reseller profile'/>
  </td>
 </tr>
</table>
</form>
<br/>

<div id='tgbody' style='width:85%;'>
<dl style='padding:15px 15px 15px 15px;text-align:justify;font-size:10pt;'>
 &nbsp;&nbsp;&nbsp;&nbsp;CompuVest invites resellers to do business with us. All discounts are based on
 quantity of purchased goods and a payment method used.<br/>
 &nbsp;&nbsp;&nbsp;&nbsp;Due to commodity nature of our business, we cannot offer a fixed discount on the products we sell.
 Please call or <a href='mailto:marat@compuvest.com'>e-mail</a>
 us with your purchase request, and we will provide you with the best possible price at a given time.<br/><br/>

<dt><b>Reseller Benefits:</b></dt>
 <dd>Blind Drop shipments directly to your customer</dd>
 <dd>Dedicated CompuVest sales representative for all questions and concerns</dd>
 <dd>Net Terms - additional rules apply, ask your agent how to qualify<br/></dd>

<dt><b>Rules for Resellers:</b></dt>
 <dd>We require a business license or a Reseller Certificate with full contact information to be faxed to us in order to set up
 a reseller account.<br/></dd>

<dt><b>International Resellers:</b></dt>
 <dd><i>Payment methods:</i><br/></dd>
 <dd>All Countries - Western Union, Wire Transfer or American Express (Visa and Master card are not accepted).<br/></dd>
 <dd>Canada - Western Union, Wire Transfer, American Express, Visa or Master card.<br/></dd>
 <dd>Please visit our
 <a href="<%= application.getInitParameter("info") %>Payment.jsp">payments section</a>
 for more information on how to make the payment correctly.<br/><br/>
 Please FAX a copy of your State issued Resale License to (425) 251-5000</dd>
 </dl>
</div>

    </td>
    <td id='cvright' valign="top">

    </td>
   </tr>
  </tbody>
  </table>
 </div>

 <div id='cvfoot'></div>
</div>

</body>
</html>
